#ifndef SYS_TIMER_H
#define SYS_TIMER_H

#include "mytype.h"
#include "stm8s.h"

#ifdef _TIMER_MODULE_
#define TIM_EXT
#else
#define TIM_EXT extern
#endif

#define SYSTICK_CYCLE 1250UL //system tick timer interrupt cycle //us
#define COUNTER_10MS ((uint8_t)((10UL * 1000UL / SYSTICK_CYCLE)))
#define COUNTER_25MS ((uint8_t)((30UL * 1000UL / SYSTICK_CYCLE)))
#define COUNTER_50MS ((uint8_t)((50UL * 1000UL / SYSTICK_CYCLE)))
#define COUNTER_100MS ((uint8_t)((100UL * 1000UL / SYSTICK_CYCLE)))
#define COUNTER_125MS ((uint8_t)((125UL * 1000UL / SYSTICK_CYCLE)))

TIM_EXT uint8_t Counter_10ms;
TIM_EXT uint8_t Counter_25ms;
TIM_EXT uint8_t Counter_50ms;
TIM_EXT uint8_t Counter_100ms;
TIM_EXT uint8_t Counter_125ms;

TIM_EXT uint8_t Counter_250ms;
TIM_EXT uint8_t Counter_500ms;
TIM_EXT uint8_t Counter_1s;

TIM_EXT uint8_t SysTickCnt;
TIM_EXT uint8_t AutoTimerCnt;
TIM_EXT uint8_t PowerUpTimeCnt;
TIM_EXT uint16_t Tick16Cnt;

TIM_EXT UINT8_BITS PulseSt;
TIM_EXT UINT8_BITS WaveSt;

#define bPulse_10ms PulseSt.bits.b0
#define bPulse_25ms PulseSt.bits.b1
#define bPulse_50ms PulseSt.bits.b2
#define bPulse_100ms PulseSt.bits.b3
#define bPulse_125ms PulseSt.bits.b4
#define bPulse_250ms PulseSt.bits.b5
#define bPulse_500ms PulseSt.bits.b6
#define bPulse_1s PulseSt.bits.b7

#define bWave_100ms WaveSt.bits.b0
#define bWave_125ms WaveSt.bits.b1
#define bWave_250ms WaveSt.bits.b2
#define bWave_500ms WaveSt.bits.b3
#define bWave_1s WaveSt.bits.b4

void SysPulseCreat(void);
void SysPulseClear(void);
void TickIntHook(void);
void SysTickInit(void);

#undef TIM_EXT

#endif /* SYS_TIMER_H */
